<template>
  <a-menu @select="select" :selectedKeys="selectedKeys">
    <a-menu-item v-for="item in list" :key="item.key">{{ item.title }}</a-menu-item>
    <a-menu-item :key="common">{{$t('m.eform.localeProvider.label.other')}}</a-menu-item>
  </a-menu>
</template>

<script>

import {getAction} from '@/api/manage'
import YchConstant from "@/api/YchConstant";
import {randomString} from "../../../../utils/util";

export default {
  name: 'LocaleTableGroup',
  props: {
    groupId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      list: [],
      selectedKeys: [],
      common: randomString(32),
      url: {
        getLeftTree: YchConstant.PREFIX_EFORM + '/manage/localeProvider/getLeftTree',
      }
    }
  },
  methods: {
    select({key}) {
      this.selectedKeys = [key]
      this.$emit('select', key, key === this.common)
    }
  },
  created() {
    getAction(this.url.getLeftTree, {groupId: this.groupId}).then((res) => {
      if (res.success) {
        this.list = res.result || []
      } else {
        this.messageUtil.warning(res.message)
      }
      this.select({key: this.list.length > 0 ? this.list[0].key : this.common})
    })
  }
}
</script>
